package com.android.job.model;

import android.app.Notification;
import android.os.Handler;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.android.job.fusion.FusionCode;
import com.archermind.android.service.threadpool.TaskHandle;

public class DownloadItem
{
	public Notification notification;

	public String from = "";

	/**
	 * 待下载文件的MD5
	 */
	public String fileMD5 = "";
	/**
	* 业务id
	*/
	public String filePath;

	/**
	 * 业务名称 
	 */
	public String fileName;

	/**
	 * 文件保存的名字
	 */
	public String saveName;

	/**
	 * 文件下载时间
	 */
	public String fileDownTime;

	/**
	 * 业务下载地址
	 */
	public String url;

	/**
	 * 下载管理器中业务的当前状态
	 */
	public int status;

	/**
	 * 该下载文件总长度
	 */
	public long fileSize;

	/**
	 * 该下载文件本地保存路径  
	 */
	public String savePath;

	/**
	 * 错误信息
	 */
	public String errMsg;

	/**
	 * 下载任务
	 */
	//	private ConnectionTask task;

	/**
	 * 已经下载文件大小
	 */
	public long downLen;

	/**
	 * 回调句柄
	 */
	private Handler handler;

	/**
	 * 进度条
	 */
	private ProgressBar progressBar;

	/**
	 * 按钮
	 */
	private TextView cancelText;

	/**
	 * 下载百分比文本框
	 */
	private TextView downRate;

	/**
	 * 下载速率
	 */
	private String rate;

	/**
	 * 下载状态图标
	 */
	private ImageView statusIcon;

	/**
	 * 下载文件名文本框
	 */
	private TextView nameView;

	/**
	 * 列表组名类型 
	 */
	private int fileType;
	/**
	 * 当前文件在列表中的位置
	 */
	private int childIndex;

	public int showType;

	public int dateDistance;
	protected TaskHandle taskhandle = null;

	//	public ConnectionTask getTask()
	//	{
	//		return task;
	//	}

	//	public void setTask(ConnectionTask task)
	//	{
	//		this.task = task;
	//	}

	public MyInfo downRequest;

	public TaskHandle getTaskHandle()
	{
		return taskhandle;
	}

	public void setTaskHandle(TaskHandle task)
	{
		this.taskhandle = task;
	}

	public long getDownLen()
	{
		return downLen;
	}

	public void setDownLen(long downLen)
	{
		this.downLen = downLen;
	}

	public Handler getHandler()
	{
		return handler;
	}

	public void setHandler(Handler handler)
	{
		this.handler = handler;
	}

	public final long getLength()
	{
		return fileSize;

	}

	public final void setLength(long length)
	{
		this.fileSize = length;
	}

	public int getStatus()
	{
		return status;

	}

	public void setStatus(int status)
	{
		this.status = status;
	}

	public ProgressBar getProgressBar()
	{
		return progressBar;
	}

	public void setProgressBar(ProgressBar progressBar)
	{
		this.progressBar = progressBar;
	}

	public TextView getCancelText()
	{
		return cancelText;
	}

	public void setCancelText(TextView cancelText)
	{
		this.cancelText = cancelText;
	}

	public String getRate()
	{
		return rate;
	}

	public void setRate(String rate)
	{
		this.rate = rate;
	}

	public TextView getDownRate()
	{
		return downRate;
	}

	public void setDownRate(TextView downRate)
	{
		this.downRate = downRate;
	}

	public ImageView getStatusIcon()
	{
		return statusIcon;
	}

	public void setStatusIcon(ImageView statusIcon)
	{
		this.statusIcon = statusIcon;
	}

	public TextView getNameView()
	{
		return nameView;
	}

	public void setNameView(TextView nameView)
	{
		this.nameView = nameView;
	}

	public void setChildIndex(int childIndex)
	{
		this.childIndex = childIndex;
	}

	public int getChildIndex()
	{
		return childIndex;
	}

	public void setFileType(int fileType)
	{
		this.fileType = fileType;
	}

	public int getFileType()
	{
		return fileType;
	}

	/**
	 * 是否正在下载
	 * @return    true: 正在下载, false: 没有下载
	 */
	public boolean isDownloading()
	{
		boolean isDownloadflag = false;
		synchronized (syncStateCtrl)
		{
			// 判断状态是否为正在下载
			isDownloadflag = status == FusionCode.DOWN_PROCESSING ? true
					: false;
		}

		return isDownloadflag;
	}

	/**
	 * 下载任务状态控制同步对象
	 */
	public Object syncStateCtrl = new Object();

	/**
	 * 是否已被暂停
	 * @return    true: 处于暂停状态, false: 非暂停态
	 */
	public boolean isPaused()
	{
		boolean isPauseflag = false;
		synchronized (syncStateCtrl)
		{
			// 判断状态是否为暂停
			isPauseflag = status == FusionCode.DOWN_PAUSE ? true : false;
		}

		return isPauseflag;
	}
}
